<template>
  <!-- 导航 -->
  <div class="nav">
    <img class="logo" src="../assets/logo.png" @click="goHome" />
    <!-- <p>天翼AI|TeleAI开放平台</p> -->
    <div class="input">
      <input
        type="text"
        v-model="keyword"
        placeholder="请输入关键词搜索"
        @blur="goFocus"
      />
      <el-button
        class="button"
        type="primary"
        @click="showLogin"
        v-if="token == null"
        >登录</el-button
      >
      <img @click="personalCenter" v-else src="../assets/me.png" alt="" />
    </div>
  </div>
</template>

<script>
import { getSearchList } from "../../api/index";
export default {
  data() {
    return {
      keyword: "",
      token: null,
    };
  },
  methods: {
    // 跳转到个人中心
    personalCenter() {
      if (this.$route.path != "/personalCenter") {
        this.$router.push("/personalCenter");
        return;
      }
    },
    // 回到首页
    goHome() {
      if (this.$route.path != "/") {
        this.$router.push("/");
        return;
      }
    },
    // 搜索
    async goFocus() {
      this.$router.push({
        path: "/",
        query: {
          keyword: this.keyword,
          time: new Date().getTime(),
        },
      });
    },
    showLogin() {
      this.$store.commit("showLogin", true);
    },
    getToken() {
      this.token = localStorage.getItem("token");
    },
  },
  computed: {},
  filters: {},
  watch: {
    $route: {
      handler() {
        this.getToken();
      },
      immediate: true,
    },
  },
  mounted() {
    this.token = localStorage.getItem("token");
  },
};
</script>

<style lang="scss" scoped>
.nav {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  border-bottom: 1px solid #e3e3e3;
  .logo {
    cursor: pointer;
  }
  .input {
    display: flex;
    input {
      padding: 0.7rem;
      border-radius: 0.3rem;
      box-sizing: border-box;
      border: 1px solid #e3e3e3;
      outline: 0;
      margin-right: 1.25rem;
    }
    .button {
      cursor: pointer;
    }
    img {
      height: 2.375rem;
      vertical-align: middle;
      cursor: pointer;
    }
  }
}
@media screen and (max-width: 600px) {
  .nav {
    display: block;
    padding: 0;

    .logo {
      width: 100%;
    }
    .input {
      margin: 1.25rem;
      input {
        min-width: 12.5rem;
        padding: 0.7rem;
        border-radius: 0.3rem;
        box-sizing: border-box;
        border: 1px solid #e3e3e3;
        outline: 0;
        margin-right: 1.25rem;
      }
      img {
        height: 2.375rem;
        vertical-align: middle;
      }
    }
  }
}
@media screen and (min-width: 601px) {
  .nav {
    display: flex;
    padding: 1.25rem $overall-padding;
  }
}
</style>
